/**
This file is part of dbdjasperreport.

Copyright (C) 2008 Kue Vang aka Kou
Licensed under the Eclipse Public License, Version 1.0; 
you may not use this file except in compliance with the License. 
You may obtain a copy of the License at http://www.eclipse.org/legal/epl-v10.html 
Unless required by applicable law or agreed to in writing, software 
distributed under the License is distributed on an "AS IS" BASIS, 
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
See the License for the specific language governing permissions and limitations 
under the License.
**/

class ReportSystemController {
    
    def index = { redirect(action:list,params:params) }

    // the delete, save and update actions only accept POST requests
    def allowedMethods = [delete:'POST', save:'POST', update:'POST']

    def list = {
        if(!params.max) params.max = 20
        [ reportSystemList: ReportSystem.list( params ) ]
    }

    def show = {
        def reportSystem = ReportSystem.get( params.id )

        if(!reportSystem) {
            flash.message = "ReportSystem not found with id ${params.id}"
            redirect(action:list)
        }
        else { return [ reportSystem : reportSystem ] }
    }

    def delete = {
        def reportSystem = ReportSystem.get( params.id )
        if(reportSystem) {
            reportSystem.delete()
            flash.message = "ReportSystem ${params.id} deleted"
            redirect(action:list)
        }
        else {
            flash.message = "ReportSystem not found with id ${params.id}"
            redirect(action:list)
        }
    }

    def edit = {
        def reportSystem = ReportSystem.get( params.id )

        if(!reportSystem) {
            flash.message = "ReportSystem not found with id ${params.id}"
            redirect(action:list)
        }
        else {
            return [ reportSystem : reportSystem ]
        }
    }

    def update = {
        def reportSystem = ReportSystem.get( params.id )
        if(reportSystem) {
            reportSystem.properties = params
            if(!reportSystem.hasErrors() && reportSystem.save()) {
                flash.message = "ReportSystem ${params.id} updated"
                redirect(action:show,id:reportSystem.id)
            }
            else {
                render(view:'edit',model:[reportSystem:reportSystem])
            }
        }
        else {
            flash.message = "ReportSystem not found with id ${params.id}"
            redirect(action:edit,id:params.id)
        }
    }

    def create = {
        def reportSystem = new ReportSystem()
        reportSystem.properties = params
        return ['reportSystem':reportSystem]
    }

    def save = {
        def reportSystem = new ReportSystem(params)
		reportSystem.setDateCreated(new Date())
        if(!reportSystem.hasErrors() && reportSystem.save()) {
            flash.message = "ReportSystem ${reportSystem.id} created"
            redirect(action:show,id:reportSystem.id)
        }
        else {
            render(view:'create',model:[reportSystem:reportSystem])
        }
    }
}